package com.ming.springboot.controller;

import com.ming.springboot.config.mongodb.MongoManager;
import com.ming.springboot.util.StudentDataUtil;
import com.ming.springboot.vo.MongoStudent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * Created by mqsi on 2022/5/20 16:53
 */
@RestController
@RequestMapping("/mongoStudent")
public class MongoStudentController {
	@Autowired
	MongoManager mongoManager;

	@RequestMapping("/add")
	public String add(Object objectBody){
		String strPk = UUID.randomUUID().toString();
		MongoStudent mongoStudent = new MongoStudent();
		mongoStudent.setUuid(strPk);
		mongoStudent.setName(StudentDataUtil.getSName());
		mongoStudent.setAge(StudentDataUtil.getAge());
		mongoManager.add(mongoStudent);
		return strPk;
	}

	@RequestMapping("/findByPk/{uuid}")
	public MongoStudent findByPk(@PathVariable String uuid){
		return mongoManager.findByPk(uuid, MongoStudent.class);
	}
}
